﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace MvcSystemsCommander.Models.Repository
{
    public class Repository<T> : IRepository<T>
        where T : class
    {
        private readonly DbSet<T> dbSet;

        public Repository(IUnitOfWork unitOfWork)
        {
            var efUnitOfWork = unitOfWork as UnitOfWork;
            if (efUnitOfWork == null) throw new InvalidUnitOfWorkException();
            dbSet = efUnitOfWork.GetDbSet<T>();
        }

        public void Add(T item)
        {
            dbSet.Add(item);
        }

        public void Remove(T item)
        {
            dbSet.Remove(item);
        }

        public IQueryable<T> Query()
        {
            return dbSet;
        }
    }
}